package com.funtl.my.shop.web.admin.service.impl;

import com.funtl.my.shop.domain.TbContent;
import com.funtl.my.shop.web.admin.abstracts.AbstractBaseServiceImpl;
import com.funtl.my.shop.web.admin.dao.TbContentDao;
import com.funtl.my.shop.web.admin.service.TbContentService;
import com.futl.my.shop.commons.dto.BaseResult;
import com.futl.my.shop.commons.dto.PageInfo;
import com.futl.my.shop.commons.validator.BeanValidator;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author tw
 * @version 1.0
 * @date 2020/5/24 0:06
 */
@Service
@Transactional(readOnly = true)
public class TbContentServiceImpl extends AbstractBaseServiceImpl<TbContent, TbContentDao> implements TbContentService {

    @Override
    @Transactional(readOnly = false)
    public BaseResult save(TbContent tbContent) {
        String validator = BeanValidator.validator(tbContent);
        if (validator != null) {
            return BaseResult.fail(validator);
        } else {
            tbContent.setUpdated(new Date());
            if (tbContent.getId() == null) {
                tbContent.setCreated(new Date());
                dao.save(tbContent);
            }else {
                update(tbContent);
            }
            return BaseResult.success("保存用户信息成功");
        }
    }

}
